home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue46 / Alfresco / Project1.dpr < prev   
Encoding:
Text File  |  1999-04-25  |  2.2 KB  |  94 lines

  1. program Project1;
  2.  
  3. {$IFDEF Win32}
  4. {$APPTYPE CONSOLE}
  5. {$ENDIF}
  6.  
  7. uses
  8.   SysUtils,
  9.   {$IFDEF Windows}
  10.   WinCrt,
  11.   {$ENDIF}
  12.   AAExpr in 'AAExpr.pas',
  13.   AAStStk in 'AAStStk.pas',
  14.   AAChStk in 'AAChStk.pas',
  15.   AAVarLst in 'AAVarLst.pas';
  16.  
  17. var
  18.   (*****
  19.   MyStack : TaaStringStack;
  20.   i       : longint;
  21.   S       : string[15];
  22.   Expected: longint;
  23.   Value   : longint;
  24.   ec      : integer;
  25.   *****)
  26.   MyExpr  : TaaExpressionParser;
  27.   Expr    : string;
  28.   Variable: string;
  29.   DValue  : double;
  30. begin
  31.   writeln('Starting test...');
  32.   try
  33.     write('Enter an expression: ');
  34.     readln(Expr);
  35.     while (Expr <> '') do begin
  36.       MyExpr := TaaExpressionParser.Create(Expr);
  37.       try
  38.         {MyExpr.TokenPrint;}
  39.         write('Enter a variable: ');
  40.         readln(Variable);
  41.         while (Variable <> '') do begin
  42.           write('Enter a value: ');
  43.           readln(DValue);
  44.           MyExpr.Variable[Variable] := DValue;
  45.           write('Enter a variable: ');
  46.           readln(Variable);
  47.         end;
  48.         writeln(MyExpr.RPNExpression);
  49.         writeln(MyExpr.Value:20:9);
  50.       except
  51.         on E:Exception do begin
  52.           writeln(E.Message);
  53.           MyExpr.Free;
  54.         end;
  55.       end;
  56.       write('Enter an expression: ');
  57.       readln(Expr);
  58.     end;
  59.  
  60.     (****** code to test TaaStringStack...
  61.     MyStack := TaaStringStack.Create(4096);
  62.     try
  63.       for i := 1 to 200000 do begin
  64.         MyStack.Push(IntToStr(i));
  65.       end;
  66.       writeln('Count:  ', MyStack.Count);
  67.       writeln('Chunks: ', MyStack.ChunkCount);
  68.       writeln('Slack:  ', MyStack.SlackSpace);
  69.       readln;
  70.       Expected := 200000;
  71.       for i := 1 to 200000 do begin
  72.         S := MyStack.Pop;
  73.         Val(S, Value, ec);
  74.         if (ec <> 0) or (Value <> Expected) then
  75.           raise Exception.create('Invalid value popped from stack');
  76.         dec(Expected);
  77.       end;
  78.       writeln('Count:  ', MyStack.Count);
  79.       writeln('Chunks: ', MyStack.ChunkCount);
  80.       writeln('Slack:  ', MyStack.SlackSpace);
  81.       readln;
  82.     finally
  83.       MyStack.Free;
  84.     end;
  85.     ****)
  86.     
  87.   except
  88.     on E: Exception do
  89.       writeln(E.Message);
  90.   end;
  91.   writeln('Done');
  92.   readln;
  93. end.
  94.